<template>
  <div style="padding:30px;">
    <!-- <el-alert :closable="false">
      <router-view />
    </el-alert>-->
    <el-table :data="tableData" border style="width: 100%;align">
      <el-table-column align="center" label="ID" width="180" prop="id">
        <!-- <template slot-scope="scope">
  
        <span style="margin-left: 10px">{{ scope.row.id }}</span>
        </template>-->
      </el-table-column>
      <el-table-column align="center" label="分公司名称" width="180" prop="name"></el-table-column>
      <el-table-column align="center" label="分公司管理员" width="180" prop="person"></el-table-column>
      <el-table-column align="center" label="电话号码" width="180" prop="telephone"></el-table-column>
      <el-table-column align="center" label="权限类别" width="100" prop="usertype">
        <!-- <template slot-scope="scope">
        <el-popover trigger="hover" placement="top">
  
          <div slot="reference" class="name-wrapper">
            <el-tag size="medium">{{ scope.row.usertype }}</el-tag>
          </div>
        </el-popover>
        </template>-->
      </el-table-column>
      <el-table-column align="center" label="操作">
        <template slot-scope="scope">
          <el-button size="mini" @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
          <el-button size="mini" type="danger" @click="handleDelete(scope.$index, scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <v-pagination
     style="margin-top:20px"
      @page-change="pageChange"
      @page-size-change="pageSizeChange"
      :total="total"
      :page-size="pageSize"
      :layout="['total', 'prev', 'pager', 'next', 'sizer', 'jumper']"
    ></v-pagination>
  </div>
</template>

<!-- 引入组件库 -->

<script>
import { hqfgs } from "@/api/zuzhijiagou";
import { getToken, gettype, getid } from "@/utils/auth";

import axios from "axios";
export default {
  name: "DragTable",

  data() {
    return {
      list: null,
      pm: {
        cid: "",
        page: 1,
        pageSize: 10
      },
      loading: false,
      pageIndex: 1,
      pageSize: 10,
      total: 1,

      tableData: []
    };
  },
  created() {
    var id = getid();
    this.pm.cid = id;

    this.findList();
  },
  methods: {
    findList() {
      var resdata = {
        cid: this.pm.cid,
        page: this.pageIndex,
        pageSize: this.pageSize
      };
      // 模拟后台接口
      this.loading = true;
      hqfgs(resdata)
        .then(response => {
          console.log(response);
          this.tableData = response.data.object;
          console.log(111111);

          this.total = response.data.total;
          this.loading = false;
        })
        .catch(e => {
          this.loading = false;
        });
    },
    // 编辑的操作
    handleEdit(index, row) {
      console.log(index, row);
    },
    // 删除的操作
    handleDelete(index, row) {
      console.log(index, row);
      this.$confirm("此操作将永久删除该分公司, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          axios.get("http://47.102.125.229:8888/account/del?id=" + row.id, {
            headers: {
              "Content-Type": "application/json",
              token: getToken(),
              type: 1
            }
          });
          // this.$message({
          //   type: 'success',
          //   message: '删除成功!'
          // });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除"
          });
        });
    },

    pageChange(pageIndex) {
      this.pageIndex = pageIndex;
      this.findList();
      console.log(pageIndex);
    },
    pageSizeChange(pageSize) {
      this.pageIndex = 1;
      this.pageSize = pageSize;
      this.findList();
    }
    // 编辑删除的操作
  }
};
</script>

<style>

.sortable-ghost {
  opacity: 0.8;
  color: #fff !important;
  background: #42b983 !important;
}
.el-alert__content {
  width: 100%;
}
</style>

<style scoped>
.icon-star {
  margin-right: 2px;
}
.drag-handler {
  width: 20px;
  height: 20px;
  cursor: pointer;
}
.show-d {
  margin-top: 15px;
}
/* .el-alert__content {
  width: 50%;
} */
.text {
  font-size: 14px;
}

.item {
  margin-bottom: 18px;
}

.clearfix:before,
.clearfix:after {
  display: table;
  content: "";
}
.clearfix:after {
  clear: both;
}

.box-card {
  width: 480px;
}
.el-alert__content {
  width: 100%;
}
</style>
